package kr.or.javacafe.app04.controller;

import java.util.Locale;

import kr.or.javacafe.demo.domain.RankData;
import kr.or.javacafe.demo.domain.RssData;
import kr.or.javacafe.demo.service.DemoService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * Handles requests for the application home page.
 */
@Controller
@RequestMapping("/app/04")
public class App04Controller {
	
	@Autowired
	DemoService demoService;
	
	private static final Logger logger = LoggerFactory.getLogger(App04Controller.class);
		

	@RequestMapping(value = "/main", method = RequestMethod.GET)
	public String main(Locale locale, Model model) {
		
		//model.addAttribute("_appCode", "04");
		
		//Naver Rank
		RankData param = new RankData();
		param.setServiceName("NAVER_RANK");
		param.setServiceKey("http://openapi.naver.com/search?query=nexearch&target=rank&key=c1b406b32dbbbbeee5f2a36ddc14067f");
		
		RankData rank = demoService.getRankResult(param);
		model.addAttribute("_rank", rank);

		
		// Naver Diary
		RssData param_Diary = new RssData();
		param.setServiceName("NAVER_DIARY");
		param.setServiceKey("http://naver_diary.blog.me/rss");
			
		RssData naverDiary = demoService.getRssResult(param_Diary);
		model.addAttribute("_naverDiary", naverDiary);
		
		return "app04/main";
	}
	
/*	@RequestMapping(value = "/rank", method = RequestMethod.GET)
	public String rank(Locale locale, Model model) {

		RankData param = new RankData();
		param.setServiceName("NAVER_RANK");
		param.setServiceKey("http://openapi.naver.com/search?query=nexearch&target=rank&key=c1b406b32dbbbbeee5f2a36ddc14067f");
		
		RankData rank = demoService.getRankResult(param);
		model.addAttribute("_rank", rank);
		
		return "demo/rank";
	}
*/

	
	
	
}
